<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form ref="queryFormRef" :inline="true" :model="queryParams" class="-mb-15px" label-width="85px">
      <el-form-item label="项目编号" prop="projectNumber">
        <el-input
          v-model="queryParams.projectNumber" placeholder="请输入项目编号" clearable @keyup.enter="handleQuery"
          class="!w-140px" />
      </el-form-item>
      <el-form-item label="纳税人属性" prop="taxpayerAttribute">
        <el-select v-model="queryParams.taxpayerAttribute" placeholder="请选择纳税人属性" clearable class="!w-140px">
          <el-option
            v-for="dict in getIntDictOptions(DICT_TYPE.OA_TAXPAYER_ATTRIBUTE)" :key="dict.value"
            :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="重点企业" prop="isKeyEnterprise">
        <el-select v-model="queryParams.isKeyEnterprise" placeholder="请选择是否为重点企业" clearable class="!w-140px">
          <el-option
            v-for="dict in getIntDictOptions(DICT_TYPE.OA_IS_OR_NO)" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="公司名称" prop="companyName">
        <el-input
          v-model="queryParams.companyName" placeholder="请输入公司名称" clearable @keyup.enter="handleQuery"
          class="!w-140px" />
      </el-form-item>
      <el-form-item label="审批结果" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择审批结果" clearable class="!w-140px">
          <el-option
            v-for="dict in getIntDictOptions(DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS)" :key="dict.value"
            :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="项目状态" prop="projectStatus">
        <el-select v-model="queryParams.projectStatus" placeholder="请选择项目状态" clearable class="!w-140px">
          <el-option
            v-for="dict in getIntDictOptions(DICT_TYPE.OA_PROJECT_STATUS)" :key="dict.value"
            :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery">
          <Icon class="mr-5px" icon="ep:search" />
          搜索
        </el-button>
        <el-button @click="resetQuery">
          <Icon class="mr-5px" icon="ep:refresh" />
          重置
        </el-button>
        <el-button
          type="success" plain @click="handleExport" :loading="exportLoading"
          v-hasPermi="['oa:project-management:dept-export']">
          <Icon icon="ep:download" class="mr-5px" /> 导出
        </el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="项目编号" align="center" prop="projectNumber" min-width="220" />
      <el-table-column label="公司名称" align="center" prop="companyName" min-width="250" />
      <el-table-column label="法人姓名" align="center" prop="legalPerson" width="100" />
      <el-table-column label="法人电话" align="center" prop="legalPersonPhone" width="120" />
      <el-table-column label="招商负责人" align="center" prop="investmentPromotionOfficer" width="100" />
      <el-table-column label="注册园区及平台" align="center" prop="registeredParkPlatform" min-width="150" />
      <el-table-column label="项目类型" align="center" prop="projectType" width="140">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.OA_PROJECT_TYPE" :value="scope.row.projectType" />
        </template>
      </el-table-column>
      <el-table-column label="企业联系人" align="center" prop="enterpriseContact" width="100" />
      <el-table-column label="企业电话" align="center" prop="enterpriseContactPhone" width="120" />
      <el-table-column label="介绍人或下级平台" align="center" prop="introducerOrSubPlatform" min-width="150" />
      <el-table-column label="申请人" align="center" prop="userName" width="100" />
      <el-table-column label="项目状态" align="center" prop="projectStatus" width="100">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.OA_PROJECT_STATUS" :value="scope.row.projectStatus" />
        </template>
      </el-table-column>
      <el-table-column label="纳税人属性" align="center" prop="taxpayerAttribute" width="110">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.OA_TAXPAYER_ATTRIBUTE" :value="scope.row.taxpayerAttribute" />
        </template>
      </el-table-column>
      <el-table-column label="收费金额" align="center" prop="serviceFee" width="100" />
      <el-table-column label="税收情况" align="center" prop="taxSituation" min-width="150" />
      <el-table-column label="返税比例" align="center" prop="taxRefundRatio" min-width="150" />
      <el-table-column label="项目确认人" align="center" prop="registrantName" width="100" />
      <el-table-column label="审批结果" align="center" prop="status" width="100">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="120" fixed="right">
        <template #default="scope">
          <el-button v-hasPermi="['oa:project-management:query']" link type="primary" @click="handleDetail(scope.row)">
            详情
          </el-button>
          <el-button
            v-hasPermi="['oa:project-management:query']" link type="primary"
            @click="handleProcessDetail(scope.row)">
            进度
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize"
      @pagination="getList" />
  </ContentWrap>
</template>

<script lang="ts" setup>
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import { ProjectManagementApi, ProjectManagementVO } from '@/api/oa/projectmanagement'
import * as ProcessInstanceApi from '@/api/bpm/processInstance'

defineOptions({ name: 'ProjectManagementDeptIndex' })

const message = useMessage() // 消息弹窗
const router = useRouter() // 路由
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const exportLoading = ref(false) // 导出的加载中
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  projectNumber: undefined,
  projectType: undefined,
  taxpayerAttribute: undefined,
  isKeyEnterprise: undefined,
  companyName: undefined,
  status: undefined,
  projectStatus: undefined,
})
const queryFormRef = ref() // 搜索的表单

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await ProjectManagementApi.getDeptProjectManagementPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 详情操作 */
const handleDetail = (row: ProjectManagementVO) => {
  router.push({
    name: 'ProjectManagementDetail',
    query: {
      id: row.id
    }
  })
}

/** 审批进度 */
const handleProcessDetail = (row) => {
  router.push({
    name: 'BpmProcessInstanceDetail',
    query: {
      id: row.processInstanceId
    }
  })
}

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    await message.exportConfirm()
    exportLoading.value = true
    const data = await ProjectManagementApi.exportDeptProjectManagement(queryParams)
    download.excel(data, '本部门项目管理.xls')
    message.success('导出成功')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script> 